class Solution {
public:
    /**
     * 
     * @param s string字符串 
     * @return int整型
     */
    int lengthOfLongestSubstring(string s) {
        // write code here
        unordered_map<char, int> dic;
        int i = -1;
        int res = 0;
        int length = s.size();
        for (int j = 0; j < length; j++) {
            if (dic.find(s[j]) != dic.end()) {
                i = max(i, dic.find(s[j])->second);
            }
            dic[s[j]] = j;
            res = max(res, j - i);
        }
        return res;
    }
};